from django.db import models
from django.contrib.postgres.fields import ArrayField


# Create your models here.
class Department(models.Model):
    name = models.CharField(max_length=32)
    enabled = models.BooleanField(default=True)
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)


class Section(models.Model):
    name = models.CharField(max_length=32)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)
    department = models.ForeignKey(Department, on_delete=models.SET_NULL, null=True)


class Group(models.Model):
    name = models.CharField(max_length=32)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)


class Employee(models.Model):
    code = models.CharField(max_length=8, help_text="员工编号")
    name = models.CharField(max_length=16, help_text="员工姓名")
    group = models.ForeignKey(Group, on_delete=models.SET_NULL, null=True)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)


class APOAccount(models.Model):
    employee = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True)
    account = models.CharField(max_length=32)
    email = models.EmailField()
    email_groups = ArrayField(models.CharField(max_length=32), null=True, blank=True, default=list)
    has_vpn = models.BooleanField(default=False)
    application_date = models.DateField(null=True, blank=True)
    has_internet = models.BooleanField(default=True, null=True, blank=True)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)


class Computer(models.Model):
    cpu = models.CharField(max_length=32, null=True, blank=True)
    memory = models.CharField(max_length=16, null=True, blank=True)
    hdd = models.CharField(max_length=8, null=True, blank=True, default="0")
    ssd = models.CharField(max_length=8, null=True, blank=True)
    gpu = models.CharField(max_length=64, null=True, blank=True)
    monitor_size = models.CharField(max_length=8, null=True, blank=True)
    network_card = models.CharField(max_length=16, null=True, blank=True, default="wireless")
    system = models.CharField(max_length=64, null=True, blank=True, default="Windows11 Pro")
    office = models.CharField(max_length=32, null=True, blank=True, default="Office 365")
    authorization = ArrayField(models.CharField(max_length=64), null=True, blank=True, default=list)
    code = models.CharField(max_length=16)
    brand = models.CharField(max_length=16, null=True, blank=True, default="Dell")
    series = models.CharField(max_length=64, null=True, blank=True)
    price = models.FloatField(null=True, blank=True)
    purchase_date = models.DateField(null=True, blank=True)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)


class AuthorizationSoftware(models.Model):
    name = models.CharField(max_length=256)
    version = models.CharField(max_length=16, null=True, blank=True)
    purchase_date = models.DateField(null=True, blank=True)
    is_subscribed = models.BooleanField(null=True, blank=True, default=False)
    next_subscribed_date = models.DateField(null=True, blank=True)
    price = models.FloatField(null=True, blank=True)
    user = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True)
    code = models.ForeignKey(Computer, on_delete=models.SET_NULL, null=True, blank=True)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)


class ApplicationInfo(models.Model):
    code = models.ForeignKey(Computer, on_delete=models.SET_NULL, null=True, blank=True)
    employee = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True)
    category = models.CharField(max_length=32, default="laptop")
    computer_name = models.CharField(max_length=32, null=True, blank=True)
    network_type = models.CharField(max_length=32, null=True, blank=True)
    is_dedicated_line = models.BooleanField(default=False, null=True, blank=True)
    enabled = models.BooleanField(default=True)
    created_date = models.DateField(auto_now_add=True)
    updated_date = models.DateField(auto_now=True)